#include <stdio.h>
#include <string.h>

int main() {
    int T;
    scanf("%d", &T);
    while (T--) {
        char s1[100100], s2[100100];
        scanf("%s%s", s1, s2);
        int l1 = strlen(s1), l2 = strlen(s2);

        int flag = 0, ans = 0, cnt = 0, i, j;
        for (i = 0, j = 0; i < l1; i++) {
            if (s1[i] != s2[j]) {
                cnt = flag * l2 + (flag > 0) * j;
                ans = (ans > cnt) ? ans : cnt;
                flag = 0;
                j = 0;
            }
            if (s1[i] == s2[j]) {
                j++;
                if (j == l2) {
                    j = 0;
                    flag++;
                }
            }
        }
        cnt = flag * l2 + (flag > 0) * j;
        ans = (ans > cnt) ? ans : cnt;
        printf("%d\n", ans);
    }
}